<template>
  <div class="container">
    <el-row class="header">
      <el-col class="asd" :span="18" align="right">
        <el-input
          v-model="data.params.menuName"
          placeholder="菜单名称"
          style="width: 120px; margin-right: 15px"
        />
        <el-select v-model="data.params.authority" class="m-2" placeholder="权限类型">
          <el-option
            v-for="item in data.authorityOption"
            :key="item.value"
            :label="item.text"
            :value="item.value"
          />
        </el-select>
      </el-col>
      <el-col :span="6" align="left">
        <el-button class="ordinary" @click="search()">搜索</el-button>
        <el-button type="danger" @click="handleDel()">批量删除</el-button>
        <el-button type="primary" @click="handleAdd()">新增</el-button>
      </el-col>
    </el-row>

    <Table
      :tableArr="data.allTableData"
      :pagination="data.page"
      :columns="data.columns"
      @delectTable="delectIds"
    >
      <template #operate="{ row }">
        <el-button size="small" class="ordinary" @click="handleEdit(row)">编辑</el-button>
      </template>
    </Table>
    <el-dialog
      v-model="data.editDialog"
      width="60%"
      title="基本信息"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <Information></Information>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="data.editDialog = false">关闭</el-button>
          <el-button type="primary" @click="handleSave()">保存</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import { reactive } from 'vue'
import tableData from './tableHeader.json'
import option from './option.json'
import Information from './information.vue'

import Table from '../components/table/table.vue'
import { ElMessageBox } from 'element-plus'

export default {
  components: {
    Table,
    Information,
  },
  setup() {
    let data = reactive({
      authorityOption: option.authorityOption,
      params: {
        menuName: '',
        authority: '',
      },
      allTableData: [
        {
          id: '1',
          abbreviation: '1',
          level: '1',
          type: '1',
          way: '1',
          rdDept: '1',
          headBy: '1',
          phone: '1',
          status: '0',
        },
        {
          id: 'ed0a6f2f23bf45c9841d629b672238aa',
          abbreviation: '平台简称',
          level: '1',
          type: '1',
          way: '1',
          rdDept: '64d9a5658cf1454185dd3551c1aaf62f',
          headBy: '负责人',
          phone: '14209834339',
          status: '1',
        },
      ],
      columns: tableData.platformTableHeader,
      page: { page: 1, limit: 10, total: 4 },
      ids: [],
      editDialog: false,
      currentRow: {},
    })
    const delectIds = (ids) => {
      data.ids = ids
    }
    const search = () => {
      data.page.page = 1
      console.log(data.params)
    }
    const handleEdit = (row) => {
      data.editDialog = true
      data.currentRow = row
      // store.commit('technologyStrength/getRowId', row.id)
    }
    const handleDel = () => {
      if(data.ids.length){
        ElMessageBox.alert('您确认删除所选中数据吗？', '提示', {
          confirmButtonText: '确认',
          callback: (action) => {
            console.log(action)
          },
        })
      }
    }
    const handleAdd = () => {
      data.editDialog = true
      // store.commit('technologyStrength/getRowId', row.id)
    }
    const handleSave = () => {
      // detailData(row.id)
      data.editDialog = false
      // store.commit('technologyStrength/getRowId', row.id)
    }
    return {
      data,
      delectIds,
      handleEdit,
      handleDel,
      handleAdd,
      handleSave,
      search,
    }
  },
}
</script>

<style lang="scss" scoped>
.container {
  background-color: white;
  // padding: 0 20px 20px;
  padding: 20px;
}
.pageName {
  font-weight: 700;
}

.el-form-item {
  .el-input {
    width: 100px;
  }

  .el-select {
    width: 100px;
  }
}

/deep/.demo-tabs > .el-tabs__content {
  max-height: 500px;
  overflow-y: scroll;
  scrollbar-width: none;
  /* Firefox */
  -ms-overflow-style: none;
  /* IE 10+ */
}

/deep/.demo-tabs > .el-tabs__content::-webkit-scrollbar {
  display: none;
  /* Chrome Safari */
}
:deep(.el-dialog__body) {
  display: block;
}
</style>
